package billings.classtasks.instructors;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import billings.classtasks.ClassTasksActivity;
import billings.classtasks.R;

public class CreateInstructor extends Activity implements OnClickListener {

	private EditText instructorFirstName;
	private EditText instructorLastName;
	private RadioGroup instructorTypesRG;
	private EditText instructorEmail;
	private EditText instructorPhone;
	private EditText instructorDepartment;
	private EditText instructorOfficeBuilding;
	private EditText instructorOfficeNumber;
	
	private Button create;
	private Button cancel;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_instructor);
        
        InstructorDAO instDAO = new InstructorDAO(this);
        instDAO.open();
        
        instructorFirstName = (EditText)findViewById(R.id.instructorFirstName);
        instructorLastName = (EditText)findViewById(R.id.instructorLastName);
        instructorTypesRG = (RadioGroup)findViewById(R.id.instructorTypeRadio);
        instructorEmail = (EditText)findViewById(R.id.instructorEmail);
        instructorPhone = (EditText)findViewById(R.id.instructorPhone);
        instructorDepartment = (EditText)findViewById(R.id.instructorDepartment);
        instructorOfficeBuilding = (EditText)findViewById(R.id.instructorOfficeBuilding);
        instructorOfficeNumber = (EditText)findViewById(R.id.instructorOfficeNumber); 
        
        create = (Button)findViewById(R.id.createInstructor);
        cancel = (Button)findViewById(R.id.cancelInstructor);
        
        create.setOnClickListener(this);
        cancel.setOnClickListener(this);
        
        List<InstructorType> allTypesList = instDAO.getAllInstructorTypes();
        
        instDAO.open();
        
        for(InstructorType it : allTypesList){
        	RadioButton rb = new RadioButton(this);
        	rb.setText(it.toString());
        	rb.setId(it.getId());
        	instructorTypesRG.addView(rb);
        }
        
        if(instructorTypesRG.getChildCount() > 0){
        	((RadioButton)instructorTypesRG.getChildAt(0)).setChecked(true);
        }
        
        instDAO.close();
	}

	public void onClick(View v) {
		Intent i;
		switch(v.getId()){
		case R.id.createInstructor:
			i = new Intent(this, ClassTasksActivity.class);
			
			//package class values
			Bundle instructorVals = new Bundle();
			instructorVals.putString("instructorFirstName", instructorFirstName.getText().toString());
			instructorVals.putString("instructorLastName", instructorLastName.getText().toString());
			instructorVals.putString("instructorEmail", instructorEmail.getText().toString());
			instructorVals.putString("instructorPhone", instructorPhone.getText().toString());
			instructorVals.putString("instructorDepartment", instructorDepartment.getText().toString());
			instructorVals.putString("instructorOfficeBuilding", instructorOfficeBuilding.getText().toString());
			instructorVals.putString("instructorOfficeNumber", instructorOfficeNumber.getText().toString());
			instructorVals.putInt("instructorTypesId", instructorTypesRG.getCheckedRadioButtonId());
			
			i.putExtra("instructorVals", instructorVals);
			i.putExtra("action", "create");
			startActivity(i);
			break;
		case R.id.cancelInstructor:
			i = new Intent(this, ClassTasksActivity.class);
			startActivity(i);
			break;
		}
		
	}

}
